﻿namespace LitBT
{
    /// <summary>
    /// 队列节点
    /// 从头到尾依次执行子节点
    /// 遇到False返回False
    /// 所有节点都返回True则返回True
    /// </summary>
    public class SequenceNode : CompositeNode
    {
        int current;
        protected override void OnStart()
        {
            current = 0;
        }

        protected override void OnStop()
        {

        }

        protected override State OnUpdate()
        {
            var child = children[current];
            switch (child.Update())
            {
                case State.Running:
                    return State.Running;
                case State.Failure:
                    return State.Failure;
                case State.Success:
                    current++;
                    break;
                default:
                    break;
            }
            return current == children.Count ? State.Success : State.Running;
        }
    }
}